﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MESCodeFile;

namespace mes_tublay
{
    //This codefile contains live notification support.
    //All forms that uses LiveNotificationSystem should
    //have a partial code here to organize all handles for the notificaiton system.
    //As of now, the frmMain is the only form which utilizes the LiveNotification control.
    //The InitializeLiveNotification is being called on frmConfig just after
    //loading the settings.
    partial class frmMain
    {
        Color notClr = Color.SeaGreen;
        int selInd = -1;
        //Live notification implementations
        public void InitializePushNotification()
        {
            //Initialize image list and bind the PushNotification to LiveNotification.
            Common.NOTIFY.NotificationSys.ImageList = imgNotification;
            liveNotify.NotifyDataBind(ref Common.NOTIFY.NotificationSys);

            //Occurs when the PushNotification has been updated
            Common.NOTIFY.NotificationUpdated += new EventHandler(delegate
            {
                liveNotify.NotifyCloseText = Common.NOTIFY.Message;
                if (Common.NOTIFY.HasError && !Common.LOGGED)
                {
                    liveNotify.NotifyTitle = "LiveNotification";
                    liveNotify.NotifyTitleImage = new Bitmap(42, 42);
                }
            });

        }
        public void InitializeLiveNotification()
        {
            
            //Initialize LiveNotification attributes
            liveNotify.NotifyOpenText = "Close Notification";
            liveNotify.NotifyCloseText = "Notification not ready...";

            //Used to display the Notification Tester Form
            mnuNotifyTester.Click += new EventHandler(delegate
            {
                frmNotifyTest frm = new frmNotifyTest();
                frm.ShowDialog();
            });
            //Occurs when the user double clicks the notification.
            liveNotify.NotifyDoubleClick += new EventHandler(delegate
            {
                if (liveNotify.SelectedIndex != -1)
                {
                    //Pull the notification from the service.
                    selInd = liveNotify.SelectedIndex;
                    CodeDynamiksCtl.Notification notify = Common.NOTIFY.Pull(selInd);
                    if (Common.NOTIFY.HasError) return;
                    //Close the LiveNotification area.
                    liveNotify.NotifyCloseArea();
                    switch (notify.ImageKey)
                    {
                        //Use the case statement to customize notification behavior
                        //by showing your own forms or performing your own function here.
                        case "PNP_TUBLAY":
                            frmDocumentsCheckList frmPNP = new frmDocumentsCheckList("PNP_TUBLAY", true);
                            frmPNP.getApplication(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString());
                            frmPNP.Initialize("Document's Checklist Manager");
                            sldMain.AddItem(frmPNP.PanelForm, "Document's Checklist Manager");
                            break;
                        case "MASSO":
                            frmDocumentsCheckList frmMASSO = new frmDocumentsCheckList("MASSO", true);
                            frmMASSO.getApplication(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString());
                            frmMASSO.Initialize("Document's Checklist Manager");
                            sldMain.AddItem(frmMASSO.PanelForm, "Document's Checklist Manager");
                            break;
                        case "MPDO":
                            frmDocumentsCheckList frmMPDO= new frmDocumentsCheckList("MUNICIPAL PLANNING AND DEVELOPMENT OFFICE",true);
                            frmMPDO.getApplication(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString());
                            frmMPDO.Initialize("Document's Checklist Manager");
                            sldMain.AddItem(frmMPDO.PanelForm, "Document's Checklist Manager");
                            break;
                        case "FIRE_DEPARTMENT":
                            frmDocumentsCheckList frmFIRE= new frmDocumentsCheckList("FIRE DEPARTMENT",true);
                            frmFIRE.getApplication(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString());
                            frmFIRE.Initialize("Document's Checklist Manager");
                            sldMain.AddItem(frmFIRE.PanelForm, "Document's Checklist Manager");
                            break;
                        case "MEO":
                            frmDocumentsCheckList frmMEO = new frmDocumentsCheckList("MUNICIPAL ENGINEERING OFFICE",true);
                            frmMEO.getApplication(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString());
                            frmMEO.Initialize("Document's Checklist Manager");
                            sldMain.AddItem(frmMEO.PanelForm, "Document's Checklist Manager");
                            break;
                        case "MHO":
                            frmDocumentsCheckList frmChecklist = new frmDocumentsCheckList("MUNICIPAL HEALTH OFFICE",true);
                            frmChecklist.getApplication(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString());
                            frmChecklist.Initialize("Document's Checklist Manager");
                            sldMain.AddItem(frmChecklist.PanelForm, "Document's Checklist Manager");
                            break;


                        case "MAYOR_OFFICE_APPROVAL":
                            frmMayorApproval frm = new frmMayorApproval();
                            frm.getApplication(notify.MetaData[4].ToString(), notify.MetaData[5].ToString());
                            frm.Initialize("Mayor Approval Form");
                            sldMain.AddItem(frm.PanelForm, "Mayor Approval Form");
                            break;
                        case "MAYOR_OFFICE":
                            //Add your own implementation here here.
                            //ShowNotificationViewer(notify);
                            myParam info = new myParam();
                            info.action = "VIEW";
                            info.msg = "VIEW BUSINESS PERMIT STATUS.";
                            info.myReferenceNumber = notify.MetaData[5].ToString();
                            info.myApplicationNumber = notify.MetaData[4].ToString();
                            info.myBusinessReferenceNumber = notify.MetaData[6].ToString();
                            //info.status = status;
                            //frmApplicationBusinessPermit frmApp = new frmApplicationBusinessPermit(info);
                            Common.PARENT.viewApplicationFormForBusinessPermit(info);
                            break;
                        case "TREASURY_DEPT_ASSESSMENT":
                            frmTreasuryeBPLS frmTeBPLS = new frmTreasuryeBPLS();
                            frmTeBPLS.SetAppNumber(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString(), notify.MetaData[7].ToString());
                            frmTeBPLS.Initialize("Treasury eBPLS");
                            sldMain.AddItem(frmTeBPLS.PanelForm, "Treasury eBPLS");
                            break;
                        case "TREASURY_DEPT_TREASURER":
                            frmTreasuryeBPLS frmTeBPLST = new frmTreasuryeBPLS();
                            frmTeBPLST.SetAppNumber(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString(), notify.MetaData[7].ToString());
                            frmTeBPLST.Initialize("Treasury eBPLS");
                            sldMain.AddItem(frmTeBPLST.PanelForm, "Treasury eBPLS");
                            break;
                        case "TREASURY_DEPT_PAYMENT":
                            frmTreasuryPayment frmTPayment = new frmTreasuryPayment();
                            frmTPayment.GetAppNumber(notify.MetaData[4].ToString(), notify.MetaData[5].ToString(), notify.MetaData[6].ToString());
                            frmTPayment.Initialize("Treasury Payment Form");
                            sldMain.AddItem(frmTPayment.PanelForm, "Treasury Payment Form");
                            break;
                        default:
                            ShowNotificationViewer(notify);
                            break;
                    }

                }
            });
            
            //Raised when the user clicks the interface button.
            liveNotify.InterfaceClick += new EventHandler(delegate(object s, EventArgs e)
            {
                if (!Common.LOGGED || liveNotify.NotifyDataCount == 0)
                {
                    if (!liveNotify.NotifiyClosed) liveNotify.NotifyCloseArea();
                }
            });

            //Used to change the color of the interface color when a notification has been detected.
            Timer tmr = new Timer();
            tmr.Interval = 500;
            tmr.Tick += new EventHandler(delegate
            {
                if (liveNotify.NotifyDataCount > 0 && liveNotify.NotifiyClosed)
                {
                    if (liveNotify.NotifyInterfaceBackColor == Color.SeaGreen)
                        liveNotify.NotifyInterfaceBackColor = Color.Red;
                    else
                        liveNotify.NotifyInterfaceBackColor = Color.SeaGreen;
                }
                else
                {
                    liveNotify.NotifyInterfaceBackColor = Color.SeaGreen;
                }
            });
            tmr.Enabled = true;
        }
        //Used for showing generic notification.
        void ShowNotificationViewer(CodeDynamiksCtl.Notification n)
        {
            //Instantiate the form
            frmNotificationViewer frm = new frmNotificationViewer();
            frm.ImageList = imgNotification;
            frm.LoadNotification(n);
            frm.Initialize("Notification #" + selInd);
            sldMain.AddItem(frm.PanelForm, "Notification #" + selInd);
            selInd = -1;
        }
    }
}